package com.bwie.controller;

import com.bwie.pojo.Owner;
import com.bwie.pojo.Result;
import com.bwie.service.OwnerService;
import com.bwie.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("owner")
public class OwnerController {

    @Autowired
    private OwnerService ownerService ;

    @Autowired
    private StoreService storeService ;

    /**
     * 跳添加业主页面
     * @param ownerId
     * @return
     */
    @RequestMapping("toAdd")
    public ModelAndView toAdd(Integer ownerId){
        ModelAndView modelAndView = new ModelAndView("/owner/add");
        Owner owner = ownerService.findById(ownerId);
        modelAndView.addObject("owner",owner);
        return modelAndView ;
    }

    /**
     * 添加页面
     * @param owner
     * @return
     */
    @RequestMapping("add")
    @ResponseBody
    public Result add(@RequestBody Owner owner){
        return ownerService.add(owner);
    }

    /**
     * 商铺下拉框
     * @return
     */
    @RequestMapping("selectStoreList")
    @ResponseBody
    public Result selectStoreList(){
        return storeService.selectStoreList();
    }

}
